package com.party.service.noticerelation.impl;

import com.party.common.Page;
import com.party.mapper.NoticeRelationMapper;
import com.party.model.NoticeRelation;
import com.party.model.NoticeRelationExample;
import com.party.service.noticerelation.NoticeRelationService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: beyond
 * Date: 14-9-18
 * Time: 下午10:38
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class NoticeRelationServiceImpl implements NoticeRelationService {

    @Resource
    NoticeRelationMapper noticeRelationMapper;

    @Override
    public List<NoticeRelation>  getNoticeRelationByPrimaryKey(Integer id) {
        NoticeRelationExample noticeRelationExample=new NoticeRelationExample();
        NoticeRelationExample.Criteria criteria = noticeRelationExample.createCriteria();
        criteria.andNoticeidEqualTo(id);

        List<NoticeRelation> list=noticeRelationMapper.getListByNotices(noticeRelationExample);
        return list;
    }

    @Override
    public int updateNoticeRelationByPrimaryKey(String noticeid, String[] userids) {
        int num=0;
        if(!"".equals(userids)&&userids!=null&&!"".equals(noticeid)&&noticeid!=null){
            NoticeRelationExample noticeRelationExample=new NoticeRelationExample();
            NoticeRelationExample.Criteria criteria = noticeRelationExample.createCriteria();
            Integer noticeidInt=Integer.parseInt(noticeid);
            criteria.andNoticeidEqualTo(noticeidInt);
            noticeRelationMapper.deleteByExample(noticeRelationExample);

            for (String uid : userids) {
                NoticeRelation noticeRelation=new NoticeRelation();
                noticeRelation.setNoticeid(noticeidInt);
                Integer uidInt=Integer.parseInt(uid);
                noticeRelation.setUid(uidInt);
                num += noticeRelationMapper.insertSelective(noticeRelation);
            }
        }
        return num;
    }
}
